﻿<!DOCTYPE html>
<html>

<head>
    <meta charset='utf-8'/>
    <title>pop lock</title>
    <meta name='viewport'
          content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no'
    />

    <meta name="renderer" content="webkit"/>
    <meta name='apple-mobile-web-app-capable' content='yes'/>
    <meta name='full-screen' content='true'/>
    <meta name='x5-fullscreen' content='true'/>
    <meta name='360-fullscreen' content='true'/>
    <meta name="laya" screenorientation="landscape"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta http-equiv='expires' content='0'/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <script src="js/jquery.js"></script>
    <script src="js/rem.js"></script>
    <style type="text/css">

        .mask {
            position: fixed;
            width: 100%;
            height: 100%;
            top: 0;
            left: 0;
            background: rgba(155, 205, 230, 1);
            z-index: 10;
            display: block;
        }

        * {
            margin: 0;
            padding: 0;
        }

        .tip_mask {
            position: fixed;
            width: 100%;
            height: 100%;
            z-index: 100;
        }

        ._tip_mask {
            position: relative;
            height: 80%;
            width: 6.0rem;
            margin: 15% auto;
        }

        .mask_bg {
            position: absolute;
            top: 0;
            width: 100%;
            z-index: 10;
        }
        .btn_download{
            position: absolute;
            top: 5.95rem;
            left: 12%;
            width: 75%;
            z-index: 11;
        }
    </style>
</head>
<body style='margin:0;overflow:none;overflow-x:hidden;overflow-y:hidden;background-color: #000;'>

<div class="mask"></div>

<div class="tip_mask" style="display: none">
    <div class="_tip_mask">
        <img src="image/mask_bg.png" class="mask_bg">
        <img src="image/btn_download.png" class="btn_download" id="download">
    </div>
</div>

<script>
    var getini;

    function getinfo() {
        var url = window.document.location.href.toString();
        var u = url.split("?");
        if (typeof(u[1]) == "string") {
            var get = {};
            get['domain'] = u[0];
            u = u[1].split("&");
            for (var i in u) {
                var j = u[i].split("=");
                get[j[0]] = j[1];
            }
            return get;
        }
        else {
            return {};
        }
    }


    function getParam() {
        if (!getini) getini = getinfo();
        return getini;
    }
</script>
<script type="text/javascript" src="libs/min/laya.core.min.js"></script>
<script type="text/javascript" src="libs/min/laya.html.min.js"></script>
<script type="text/javascript" src="libs/min/laya.ui.min.js"></script>
<script src="js/ui/layaUI.max.all.js"></script>
<script src="js/main.js"></script>

<!--http://localhost:63342/cf-game/h5-update/index.html?_ijt=8ld66467006vdl4uk58ir5nq4o&token=fac860d744306e3d78dcdcd549738fb1&gameId=1&gameMode=1&guide=0&speed=10&total=1-->
<script>


    var host = "game.zbswzn.cn"

    // var host = "10.168.1.182:8085"

    function doPay() {
        /iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) ? showPay() : native.showPay()
    }

    function doClose() {
        /iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) ? closeGame() : native.closeGame()
    }

    function doSign(gameId, gameMode, payToken, data) {
        return /iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase()) ? getSign(gameId, gameMode, payToken, data + "") : native.getSign(gameId, gameMode, payToken, data + "")
    }


    var gameData = {};

    var param = getParam();

    var phone = param.phone;
    var channel = param.channel;
    var channelId = param.channelId;


    function createNewUser() {
        $.ajax({
            url: 'http://' + host + '/user/noAuth/createAndLogin',
            type: 'post',
            async: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: JSON.stringify({'phone': phone, 'channelId': channelId, 'channel': channel}),//这里使用json对象
            success: function (data) {
                param.token = data.data
                if (!param.token || param.token.length <= 0) {
                    //没有获取到
                    doClose();
                }
            },
            fail: function () {
                //调用约定方法，关闭游戏
                doClose();
            }
        });
    }


    if (phone && phone.length == 11 && channel && channel.length > 0 && channelId) {
        createNewUser();
    }


    //用户token
    var gameId = param.gameId;
    var gameMode = param.gameMode;


    function h5GameCheck() {
        $.ajax({
            url: 'http://' + host + '/h5GameXjkdCheck',
            type: 'get',
            async: false,
            beforeSend: function (request) {
                request.setRequestHeader("userToken", param.token);
            },
            data: {gameId: gameId, gameMode: gameMode},
            success: function (data) {
                param.total = data.data.bestScore
                param.guide = data.data.needGuide ? 1 : 0
            },
            fail: function () {
                //调用约定方法，关闭游戏
                doClose();
            }
        });
    }


    h5GameCheck();


    function updateScore(scoreDate) {
        if (gameData.total < scoreDate) {
            gameData.total = scoreDate;
        }
        var data = scoreDate;
        $.ajax({
            url: 'http://' + host + '/uploadScore',
            type: 'post',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            async: false,
            beforeSend: function (request) {
                request.setRequestHeader("userToken", param.token);
            },
            data: JSON.stringify({
                'gameId': gameId,
                'gameMode': gameMode,
                'payToken': "xjkd",
                'score': data,
                'sign': "xjkd"
            }),//这里使用json对象
            success: function (data) {
                if (data.data) {
                    gameData.total = data.data;
                }
            },
            fail: function () {
                //调用约定方法，关闭游戏
                doClose();
            }
        });
    }


    beginGame(param.guide, parseInt(param.speed ? param.speed : 5), 1, param.total ? parseInt(param.total) : 0, function (score) {
        updateScore(score)
    }, function () {
        this.setGameing(true);
    });

    $("#download").click(function () {
        if (/iphone|ipad|ipod/.test(navigator.userAgent.toLowerCase())) {
            window.location.href = "http://itunes.apple.com/app/id1324911162?mt=8"
        } else {
            window.location.href = "http://a.app.qq.com/o/simple.jsp?pkgname=com.canfu.pcg"
        }
    })

</script>
</body>

</html>